package org.jeecg.modules.charge.controller;

import java.util.*;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.google.common.collect.Lists;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.vo.LoginUser;

import org.jeecg.common.util.SsoUtil;
import org.jeecg.common.util.StringUtils;
import org.jeecg.entity.basedata.BaseRoom;
import org.jeecg.entity.charge.ChargeFeeitem;
import org.jeecg.entity.charge.ChargeStandard;
import org.jeecg.enums.charge.ChargeComputingTypeEnum;
import org.jeecg.modules.charge.service.IChargeFeeitemService;
import org.jeecg.modules.charge.service.IChargeStandardService;

import java.math.BigDecimal;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.charge.service.impl.ChargeStandardServiceImpl;
import org.jeecg.modules.charge.vo.ChargeStandardReqVo;
import org.jeecg.modules.system.service.ISysUserRoleService;
import org.jeecg.service.IFeignBaseDataService;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @Description: 收费标准
 * @Author: jeecg-boot
 * @Date: 2019-07-31
 * @Version: V1.0
 */
@Slf4j
@Api(tags = "收费标准")
@RestController
@RequestMapping("/b/charge/chargeStandard")
public class ChargeStandardController {
    @Autowired
    private IChargeStandardService chargeStandardService;
    @Autowired
    private ChargeStandardServiceImpl chargeStandardServiceImpl;
    @Autowired
    private IChargeFeeitemService feeitemService;
    @Autowired
    private IFeignBaseDataService feignBaseDataService;
    @Autowired
    private ISysUserRoleService sysUserRoleService;

    /**
     * 分页列表查询
     *
     * @param chargeStandard
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "收费标准-分页列表查询")
    @ApiOperation(value = "收费标准-分页列表查询", notes = "收费标准-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<ChargeStandard>> queryPageList(ChargeStandard chargeStandard,
                                                       @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                       HttpServletRequest req) {
        Result<IPage<ChargeStandard>> result = new Result<IPage<ChargeStandard>>();
        try {
            Page<ChargeStandard> page = new Page<ChargeStandard>(pageNo, pageSize);
            chargeStandard.setSqlMap(sysUserRoleService.dataScopeProjectOnlyFilter(SsoUtil.getLoginUser(),"p",chargeStandard.getMenuPath(),null,null));
            List<ChargeStandard> list = chargeStandardService.findPage(page,chargeStandard);
            page.setRecords(list);
            result.setSuccess(true);
            result.setResult(page);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败");
        }
        return result;
    }

    /**
     * 添加
     *
     * @param chargeStandard
     * @return
     */
    @AutoLog(value = "收费标准-添加")
    @ApiOperation(value = "收费标准-添加", notes = "收费标准-添加")
    @PostMapping(value = "/add")
    public Result<ChargeStandard> add(@RequestBody ChargeStandard chargeStandard) {
        Result<ChargeStandard> result = new Result<ChargeStandard>();
        try {
            if (StringUtils.isNotEmpty(chargeStandard.getRoomId())) {
                ChargeFeeitem chargeFeeitem =   feeitemService.getById(chargeStandard.getItemId());
                if (chargeFeeitem != null){
                    chargeStandard.setItemName(chargeFeeitem.getFeeName());
                    chargeStandard.setSubjectsId(chargeFeeitem.getSubjectsId());
                }
                BaseRoom room =  feignBaseDataService.getByRoomIds(chargeStandard.getRoomId(),SsoUtil.getLoginUser().getTenantId()); //chargeStandardService.getByRoom(chargeStandard.getRoomId());//?
                //按月收费
                if (ChargeComputingTypeEnum.CHARGE_COMPUTING_TYPE_MONTH.getCode() == chargeStandard.getComputingType()) {
                    chargeStandard.setFeeCurrent(new BigDecimal(chargeStandard.getPrice()));
                } else {
                    //单价乘以面积
                    Integer number = room.getBuildArea().compareTo(new BigDecimal(0));
                    //建筑面积 - 计算单位
                    if (room.getBuildArea() != null && number > 0 && chargeStandard.getUnitAccount() != null) {
                        //单价
                        BigDecimal num = new BigDecimal(chargeStandard.getPrice());
                        BigDecimal money1 = num.multiply(room.getBuildArea());
                        money1 = money1.setScale(chargeStandard.getUnitAccount(), BigDecimal.ROUND_HALF_UP);
                        //当前收费金额
                        chargeStandard.setFeeCurrent(money1);
                    } else {
                        chargeStandard.setFeeCurrent(BigDecimal.ZERO);
                    }
                }
            }else {
                return Result.error("请选择房间！");
            }
            chargeStandard.setCreateTime(new Date());
            chargeStandard.setCreateBy(SsoUtil.getLoginUser().getId());
            chargeStandardService.save(chargeStandard);
            result.success("添加成功！");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败");
        }
        return result;
    }

    /**
     * 编辑
     *
     * @param chargeStandard
     * @return
     */
    @AutoLog(value = "收费标准-编辑")
    @ApiOperation(value = "收费标准-编辑", notes = "收费标准-编辑")
    @PutMapping(value = "/edit")
    public Result<ChargeStandard> edit(@RequestBody ChargeStandard chargeStandard) {
        Result<ChargeStandard> result = new Result<ChargeStandard>();
        ChargeStandard chargeStandardEntity = chargeStandardService.getById(chargeStandard.getId());
        if (chargeStandardEntity == null) {
            result.error500("未找到对应实体");
        } else {
            try {
                if (StringUtils.isNotEmpty(chargeStandard.getRoomId())) {
                    BaseRoom room = feignBaseDataService.getByRoomIds(chargeStandard.getRoomId(),SsoUtil.getLoginUser().getTenantId());    //chargeStandardService.getByRoom(chargeStandard.getRoomId());
                    if (ChargeComputingTypeEnum.CHARGE_COMPUTING_TYPE_MONTH.getCode() == chargeStandard.getComputingType()) {
                        chargeStandard.setFeeCurrent(new BigDecimal(chargeStandard.getPrice()));
                    } else {
                        Integer number = room.getBuildArea().compareTo(new BigDecimal(0));
                        if (room.getBuildArea() != null && number > 0 && chargeStandard.getUnitAccount() != null) {
                            BigDecimal num = new BigDecimal(chargeStandard.getPrice());
                            BigDecimal money1 = num.multiply(room.getBuildArea());
                            money1 = money1.setScale(chargeStandard.getUnitAccount(), BigDecimal.ROUND_HALF_UP);
                            chargeStandard.setFeeCurrent(money1);
                        } else {
                            chargeStandard.setFeeCurrent(BigDecimal.ZERO);
                        }
                    }
                }
                chargeStandard.setUpdateBy(SsoUtil.getLoginUser().getId());
                chargeStandard.setUpdateTime(new Date());
                boolean ok = chargeStandardService.updateById(chargeStandard);
                if (ok) {
                    result.success("修改成功!");
                }
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                result.error500("操作失败");
            }
        }

        return result;
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "收费标准-通过id删除")
    @ApiOperation(value = "收费标准-通过id删除", notes = "收费标准-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
        try {
            chargeStandardService.removeById(id);
        } catch (Exception e) {
            log.error("删除失败", e.getMessage());
            return Result.error("删除失败!");
        }
        return Result.ok("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "收费标准-批量删除")
    @ApiOperation(value = "收费标准-批量删除", notes = "收费标准-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result<ChargeStandard> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        Result<ChargeStandard> result = new Result<ChargeStandard>();
        if (ids == null || "".equals(ids.trim())) {
            result.error500("参数不识别！");
        } else {
            this.chargeStandardService.removeByIds(Arrays.asList(ids.split(",")));
            result.success("删除成功!");
        }
        return result;
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "收费标准-通过id查询")
    @ApiOperation(value = "收费标准-通过id查询", notes = "收费标准-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<ChargeStandard> queryById(@RequestParam(name = "id", required = true) String id) {
        Result<ChargeStandard> result = new Result<ChargeStandard>();
        ChargeStandard chargeStandard = chargeStandardService.getById(id);
        if (chargeStandard == null) {
            result.error500("未找到对应实体");
        } else {
            result.setResult(chargeStandard);
            result.setSuccess(true);
        }
        return result;
    }


    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response,
                                 @RequestParam("projectId") String projectId) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            MultipartFile file = entity.getValue();// 获取上传文件对象
            ImportParams params = new ImportParams();
            params.setNeedSave(true);
            try {
                int successNum = 0;
                int failureNum = 0;
                int row = 1;
                StringBuilder failureMsg = new StringBuilder();
                List<ChargeStandard> saveList = Lists.newArrayList();
                List<ChargeStandard> listChargeStandards = ExcelImportUtil.importExcel(file.getInputStream(), ChargeStandard.class, params);
                for (ChargeStandard chargeStandard : listChargeStandards) {
                    if (StringUtils.isBlank(chargeStandard.getProjectName())){
                        failureMsg.append("<br/>第").append(row).append("行：请输入项目名称; ");
                        failureNum++;
                        row++;
                        continue;
                    }
                    //项目名称校验
                    String projectName = chargeStandardService.queryProjectName(projectId);
                    if (chargeStandard.getProjectName().trim().equals(projectName)) {
                        chargeStandard.setProjectId(projectId);
                        chargeStandard.setProjectName(projectName);
                    } else {
                        failureMsg.append("<br/>第").append(row).append("行：请检查项目名称与选择名称是否一致; ");
                        failureNum++;
                        row++;
                        continue;
                    }
                    if (StringUtils.isBlank(chargeStandard.getFloorName())) {
                        failureMsg.append("<br/>第").append(row).append("行：请输入楼宇名称; ");
                        failureNum++;
                        row++;
                        continue;
                    }
                    //查询楼宇ID
                    String floorId = chargeStandardService.queryFloorId(projectId, chargeStandard.getFloorName().trim());
                    if (StringUtils.isEmpty(floorId)) {
                        failureMsg.append("<br/>第").append(row).append("行：请输入正确的楼宇名称; ");
                        failureNum++;
                        row++;
                        continue;
                    }
                    chargeStandard.setFloorId(floorId);
                    String roomName = chargeStandard.getRoomName();
                    if (chargeStandard.getRoomName().contains(".")) {
                        roomName = chargeStandard.getRoomName().substring(0, chargeStandard.getRoomName().indexOf("."));
                    }
                    //查询房间ID
                    String roomId = chargeStandardService.queryRoomId(floorId, roomName.trim());
                    if (StringUtils.isEmpty(roomId)) {
                        failureMsg.append("<br/>第").append(row).append("行：请输入正确的房间名称; ");
                        failureNum++;
                        row++;
                        continue;
                    }
                    chargeStandard.setRoomId(roomId);
                    if (StringUtils.isBlank(chargeStandard.getItemName()) && StringUtils.isBlank(chargeStandard.getItemCode())){
                        failureMsg.append("<br/>第").append(row).append("行：请填写收费项; ");
                        failureNum++;
                        row++;
                        continue;
                    }
                    //如果添加了收费项编码 优先以编码优先
                    ChargeFeeitem chargeFeeitem = new ChargeFeeitem();
                    if (StringUtils.isNotBlank(chargeStandard.getItemCode())){
                        chargeFeeitem = feeitemService.getFeeitemByCode(chargeStandard.getItemCode().trim());
                        if (chargeFeeitem == null){
                            failureMsg.append("<br/>第").append(row).append("行;填写的收费项编号["+chargeStandard.getItemCode()+"]系统中不存在 ");
                            failureNum++;
                            row++;
                            continue;
                        }
                    } else { //校验收费项名称
                        //查询系统是否存在
                        List<ChargeFeeitem> feeitemList = feeitemService.queryItemByName(chargeStandard.getItemName().trim());
                        if (feeitemList.size() <= 0) {
                            failureMsg.append("<br/>第").append(row).append("行;填写的收费项名称["+chargeStandard.getItemName()+"]系统中不存在 ");
                            failureNum++;
                            row++;
                            continue;
                        }
                        if (feeitemList.size() > 1){
                            failureMsg.append("<br/>第").append(row).append("行;填写的收费项名称["+chargeStandard.getItemName()+"]在系统中有多个,无法识别,请填写收费项编号");
                            failureNum++;
                            row++;
                            continue;
                        }
                        chargeFeeitem = feeitemList.get(0);
                    }
                    //查询该房间是否已经配置收费标准
                    Integer count = chargeStandardService.existQueryStandard(roomId,chargeFeeitem.getId());
                    if (count > 0) {
                        failureMsg.append("<br/>第").append(row).append("行：该房间已经设置收费标准; ");
                        failureNum++;
                        row++;
                        continue;
                    }
//                    chargeStandard.setItemCode(chargeFeeitem.getFeeCode());
                    chargeStandard.setItemName(chargeFeeitem.getFeeName());
                    chargeStandard.setItemId(chargeFeeitem.getId());

                    if (StringUtils.isBlank(chargeStandard.getPrice())) {
                        failureMsg.append("<br/>第").append(row).append("行：请填写单价; ");
                        failureNum++;
                        row++;
                        continue;
                    }
                    chargeStandard.setPrice(chargeStandard.getPrice().trim());
                    if (StringUtils.isBlank(chargeStandard.getComputingTypeName())){
                        failureMsg.append("<br/>第").append(row).append("行：请填写计算方式; ");
                        failureNum++;
                        row++;
                        continue;
                    }
                    if (StringUtils.isBlank(chargeStandard.getUnitAccountName())) {
                        failureMsg.append("<br/>第").append(row).append("行：请填写计算单位; ");
                        failureNum++;
                        row++;
                        continue;
                    }
                    if (chargeStandard.getUnitAccountName().equals("圆")) {
                        chargeStandard.setUnitAccount(0);
                    } else if (chargeStandard.getUnitAccountName().equals("角")) {
                        chargeStandard.setUnitAccount(1);
                    } else {
                        chargeStandard.setUnitAccount(2);
                    }
                    if (chargeStandard.getComputingTypeName().trim().equals("按月收费")) {
                        chargeStandard.setComputingType(0);
                        BigDecimal price = new BigDecimal(chargeStandard.getPrice().trim());
                        BigDecimal feeCurrent = price.setScale(chargeStandard.getUnitAccount(), BigDecimal.ROUND_HALF_UP);
                        chargeStandard.setFeeCurrent(feeCurrent);
                    } else if (chargeStandard.getComputingTypeName().trim().equals("物业费=单价*面积")) {
                        BaseRoom room = feignBaseDataService.getByRoomIds(roomId,SsoUtil.getLoginUser().getTenantId());
                        Integer number = room.getBuildArea().compareTo(new BigDecimal(0));
                        if (room.getBuildArea() != null && number > 0) {
                            BigDecimal num = new BigDecimal(chargeStandard.getPrice().trim());
                            BigDecimal money1 = num.multiply(room.getBuildArea());
                            money1 = money1.setScale(chargeStandard.getUnitAccount(), BigDecimal.ROUND_HALF_UP);
                            chargeStandard.setFeeCurrent(money1);
                        } else {
                            chargeStandard.setFeeCurrent(BigDecimal.ZERO);
                        }
                        chargeStandard.setComputingType(1);
                    } else {
                        failureMsg.append("<br/>第").append(row).append("行：请填写正确的计算方式; ");
                        failureNum++;
                        row++;
                        continue;
                    }
                    successNum++;
                    saveList.add(chargeStandard);
                }
                if (failureNum > 0) {
                    return Result.error("文件导入失败:" + failureMsg.toString());
                }
                chargeStandardService.saveBatch(saveList);
                return Result.ok("文件导入成功！数据行数:" + successNum);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                return Result.error("文件导入失败:" + e.getMessage());
            } finally {
                try {
                    file.getInputStream().close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return Result.ok("文件导入失败！");
    }

    /**
     * 租户判断是否已生成收费标准
     *
     * @return
     */
    @AutoLog(value = "收费项目查询")
    @ApiOperation(value = "收费项目查询", notes = "收费项目查询")
    @RequestMapping(value = "/getStandarTenant", method = RequestMethod.GET)
    public Result<Integer> getStandarTenant(@RequestParam(name = "roomId", required = true) String roomId,
                                            @RequestParam(name = "feeCode", required = true) String feeCode,
                                            @RequestParam(name = "tenantRoomId", required = true) String tenantRoomId) {
        Result<Integer> result = new Result<>();
        Integer number = 0;
        try {
            number = chargeStandardService.getStandarTenant(roomId, feeCode, tenantRoomId);
            result.setResult(number);
            result.setSuccess(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return result;
    }

    /**
     * 判断是否已生成收费标准
     *
     * @return
     */
    @AutoLog(value = "收费项目查询")
    @ApiOperation(value = "收费项目查询", notes = "收费项目查询")
    @RequestMapping(value = "/getCountStandardRoom", method = RequestMethod.GET)
    public Result<Integer> getCountStandardRoom(@RequestParam(name = "roomId", required = true) String roomId,
                                                @RequestParam(name = "feeId", required = true) String feeId) {
        Result<Integer> result = new Result<>();
        Integer number = 0;
        try {
            number = chargeStandardService.getCountStandardRoom(roomId, feeId);
            result.setResult(number);
            result.setSuccess(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return result;
    }

    /**
     * 批量生成收费标准
     *
     * @return
     */
    @AutoLog(value = " 批量生成收费标准")
    @ApiOperation(value = " 批量生成收费标准", notes = " 批量生成收费标准")
    @RequestMapping(value = "/postStandardAllList", method = RequestMethod.POST)
    public Result<Integer> postStandardAllList(@RequestBody ChargeStandardReqVo chargeStandardReqVo) {
        Integer numbers = 0;
        Result<Integer> result = new Result<>();
        LoginUser user = SsoUtil.getLoginUser();
        StringBuilder sb = new StringBuilder();
        try {
            String standardIds = chargeStandardReqVo.getStandardIds();
            String checkedKeys = chargeStandardReqVo.getCheckedKeys();
            if (StringUtils.isNotEmpty(standardIds) && StringUtils.isNotEmpty(checkedKeys)) {
                String ids[] = standardIds.split(",");
//				String keys[] =  checkedKeys.split(",");
                MultiValueMap<String, String> formParams = new LinkedMultiValueMap<>();
                formParams.add("roomIds", JSON.toJSONString(checkedKeys));
                List<BaseRoom> roomList = feignBaseDataService.getByRoomIdsLarge(JSON.toJSONString(checkedKeys), user.getTenantId().toString());
                List<ChargeStandard> standardList = new ArrayList<ChargeStandard>();
                for (BaseRoom room : roomList) {
                    Integer number = room.getBuildArea().compareTo(new BigDecimal(0));
                    for (int i = 0; i < ids.length; i++) {
                        ChargeStandard chargeStandard = chargeStandardService.getById(ids[i]);
                        if (chargeStandard != null) {
//                            if (StringUtils.isNotEmpty(chargeStandard.getCustomerId())) {
//                                continue;
//                            }
                            if (ChargeComputingTypeEnum.CHARGE_COMPUTING_TYPE_PRICE.getCode() == chargeStandard.getComputingType()) { // 判断计算收费的方式
                                if (room.getBuildArea() != null && number > 0 && chargeStandard.getUnitAccount() != null) {
                                    BigDecimal num = new BigDecimal(chargeStandard.getPrice());
                                    BigDecimal money1 = num.multiply(room.getBuildArea());
                                    money1 = money1.setScale(chargeStandard.getUnitAccount(), BigDecimal.ROUND_HALF_UP);
                                    chargeStandard.setFeeCurrent(money1);
                                }
                            }
                            chargeStandard.setRoomId(room.getId());
                            chargeStandard.setResident("2");
                            chargeStandard.setFloorId(room.getFloorId());
                            chargeStandard.setProjectId(room.getProjectId());
                            chargeStandard.setCreateBy(user.getId());
                            chargeStandard.setCreateTime(new Date());
                            chargeStandard.setUpdateBy(user.getId());
                            chargeStandard.setUpdateTime(new Date());
                            chargeStandard.setId(String.valueOf(IdWorker.getId()));
                            chargeStandard.setDelFlag("0");
                            chargeStandard.setItemId(chargeStandard.getItemId());
                            Integer results = chargeStandardService.getCountStandardRoom(room.getId(), chargeStandard.getItemId());
                            if (results > 0) {
                                sb.append("房间").append(room.getName()).append("已有收费项[").append(chargeStandard.getItemName()).append("]，请勿重复生成!");
                                continue;
                            }
                            standardList.add(chargeStandard);
                        }
                    }
                }
                if (standardList.size() > 0) {
                    numbers = chargeStandardService.insertList(standardList);
                    return Result.ok("处理成功共计生成" + numbers + "条");
                } else {
                    return Result.error("处理失败共计生成" + numbers + "条." + sb.toString());
                }
            } else {
                return Result.error("请选择需要生成的目标！");
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return Result.error("系统繁忙，生成失败！");
        }
    }


    /**
     * 批量修改收费标准
     *
     * @param chargeStandard
     * @return
     */
    @AutoLog(value = "批量修改收费标准")
    @ApiOperation(value = "批量修改收费标准", notes = "批量修改收费标准")
    @PostMapping(value = "/updateAll")
    public Result<ChargeStandard> updateAll(@RequestBody ChargeStandard chargeStandard) {
        Result<ChargeStandard> result = new Result<ChargeStandard>();
        try {
            chargeStandardServiceImpl.updateAll(chargeStandard);
            result.success("修改成功！");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败");
        }
        return result;
    }


    /**
     * 批量删除收费标准
     *
     * @return
     */
    @RequestMapping(value = "/getStandarAllDelete", method = RequestMethod.POST)
    public Result<String> getStandarAllDelete(@RequestBody ChargeStandard chargeStandard) {
        Result<String> result = new Result<>();
        Integer results = 0;
        try {
            if (chargeStandard.getRoomIdList().size() > 0 && chargeStandard.getStandardIds().size() > 0) {
                List<String> feeCodeList = new ArrayList<String>();
                for (String id : chargeStandard.getStandardIds()) {
                    ChargeStandard standard = chargeStandardService.getById(id);
                    feeCodeList.add(standard.getItemCode());
                }
                chargeStandard.setUpdateTime(new Date());
                chargeStandard.setUpdateBy(SsoUtil.getLoginUser().getId());
                chargeStandard.setFeeCodeList(feeCodeList);
                results = chargeStandardServiceImpl.deleteStandard(chargeStandard);
            }
            result.success("删除成功！一共删除" + results + "条收费标准。");
        } catch (Exception e) {
            result.error500("删除失败！");
            log.error(e.getMessage(), e);
        }
        return result;
    }

}
